// xc_lshop/distr/manage/myteam.js
var actbill = require('../model/distribution_team.js')
Page({
  mixins: [require('../../../xc/mixins/basicMixin')],
  /**
   * 页面的初始数据
   */
  data: {
    levefiled: "all",
    loading: true,
    nav:null,
    statistics:{},
    modellist: [],
    memberinfo: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  setconfig(config){
    var update = {};
    if (config.distribution && config.distribution.distext && config.distribution.distext.center) {
      update['xtitle'] = config.distribution.distext.center.myteam
    }
    this.setData(update)
  },
  getnav: function () {
    var that = this;
    actbill.nav().then(function (res) {
      if(res.status==1){
        var updatemodel={nav:res.obj.nav,statistics:res.obj.statistics}
    
        that.setData(updatemodel)    
      }     
    })
  },
  afterlogin: function (options, config, userinfo) {
    this.setconfig(config)
    if (!config.distribution || config.distribution.status != 1) {
      wx.redirectTo({
        url: config.basic.homeurl,
      })
      return
    }
    else {
      if (userinfo['memberinfo']) {
        if (userinfo['memberinfo']['is_distribution'] == -1) {
 
          var link = "/xc_lshop/distr/info/apply"
          this.pageback(link,true)
        } else {
          this.getnav();
          this.setData({ memberinfo: userinfo.memberinfo })
          this.getpagelist(1);
        }
      } else {
        console.log("dsddd")

        this.pageback()
      }
     
    }
  },
  onNavChange(e) {
    var that = this
    if (this.data.levefiled != e.detail.name) {
      this.setData({ levefiled: e.detail.name })
      this.getpagelist(1);

    }

  },
  getpagelist(rest, strwhere) {
    var that = this
    if (rest == 1) {
      that.setData({
        modellist: []
      });
      if (!strwhere) {
        strwhere = {}
      }
      strwhere["levefiled"] = this.data.levefiled
    }
    this.setData({ isload: true })
    actbill.offset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};
      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        } else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      wx.stopPullDownRefresh();
      updatemdoel["isload"] = false

      that.setData(updatemdoel);
    })
    return;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

    this.getpagelist(1)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

    this.getpagelist(-1)
  },


})